//
//  RoomInfoLogic.m
//  QRMaster
//
//  Created by myApple on 15/12/22.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "FloorsInfoLogic.h"
#import "OperationDataBaseModel.h"

@implementation FloorsInfoLogic
{
}
-(void)insertFloorInfo:(FloorsModel *)model withCommunityId:(NSString *)communityId buildingId:(NSString *)buildingId
{
    NSMutableDictionary * staffDict = [self modelConvertDict:model];
    [staffDict setValue:communityId forKey:@"communityId"];
    [staffDict setValue:buildingId forKey:@"buildingid"];
    OperationDataBaseModel * operation = [[OperationDataBaseModel alloc]init];
    [operation insertDataTable:@"floorsInfo" withDict:staffDict];
}

/**
 *  模型转化为字典
 *
 *  @param model 楼层模型
 *
 *  @return 可变字典
 */
-(NSMutableDictionary *)modelConvertDict:(FloorsModel *)model
{
    NSMutableDictionary * staffDict = [[NSMutableDictionary alloc]init];
    [staffDict setValue:model.floorId forKey:@"floorid"];
    [staffDict setValue:model.floorName forKey:@"floorname"];
    [staffDict setValue:model.floorNo forKey:@"floorno"];
    return staffDict;
}

/**
 *  查询楼层信息
 *
 *  @param buildingId  楼栋ID
 *
 *  @param block       集群用于接收查询到的数组
 */
-(void)queryFloorsInfo:(NSString *)buildingId block:(arrBlock)arrBlock
{
    NSMutableArray *floorsArray=[[NSMutableArray alloc]init];
    OperationDataBaseModel * operation = [[OperationDataBaseModel alloc]init];
    [operation queryDataFromTable:@"floorsInfo" withCondition:[NSString stringWithFormat:@"where buildingid = %@",buildingId] block:^(FMResultSet *set) {
        while ([set next]) {
            FloorsModel *floorsModel=[[FloorsModel alloc]init];
            floorsModel.floorId=[set stringForColumn:@"floorid"];
            floorsModel.floorName=[set stringForColumn:@"floorname"];
            floorsModel.floorNo=[set stringForColumn:@"floorno"];
            [floorsArray addObject:floorsModel];
        }
        if (arrBlock) {
            arrBlock(floorsArray);
        }
    }];
}

#pragma mark ------楼层名称
-(void)queryfloorName:(NSString *)floorId block:(resultFloorName)floorName
{
    __block NSString * floorNameStr=@"";
    
    NSString * condition = [NSString stringWithFormat:@"where %@=%@",@"floorid",floorId];
    OperationDataBaseModel * operation = [[OperationDataBaseModel alloc]init];
    [operation queryDataFromTable:@"floorsinfo" withCondition:condition block:^(FMResultSet *set) {
        while ([set next]) {
            floorNameStr = [set objectForColumnName:@"floorname"];
        }
        if (floorName) {
            floorName(floorNameStr);
        }
    }];
}

/**
 *  根据集群id删除该集群下楼层信息
 *
 *  @param communityId 集群ID
 *
 */
-(void)deleteFloorsInfoWithCommunityId:(NSString *)communityId
{
    OperationDataBaseModel * operation = [[OperationDataBaseModel alloc]init];
    [operation deleteDataFromTableByCommunityId:@"floorsInfo" communityId:communityId];
}

@end
